#!/usr/bin/env bash
if [[ "$(id -u)" != "0" ]]; then sudo -sE '/home/.os/run.sh' || exit 1; exit; fi;

########## prepare
DIR=$(dirname $(realpath "${0}"));  RUN="${DIR}/_run";  INS='/opt';
MEM="${INS}/.os";  DEL="${DIR}/.del";  TMP="${DIR}/.tmp";  MSG='';
EXE="${DIR}/exec";  . "${RUN}/00.init.sh" || exit 1;

########## install
. "${RUN}/01.node.sh" || exit 1;
. "${RUN}/02.htpasswd.sh" || exit 1;
. "${RUN}/03.nginx.sh" || exit 1;
. "${RUN}/04.httpd.sh" || exit 1;
. "${RUN}/05.gogs.sh" || exit 1;
. "${RUN}/06.golang.sh" || exit 1;
. "${RUN}/07.rust.sh" || exit 1;
. "${RUN}/08.php.sh" || exit 1;
. "${RUN}/40.projector.sh" || exit 1;
. "${RUN}/41.phpstorm.sh" || exit 1;

########## permission
f_mode "${DIR}" '700' '755' 'root:root';
f_mode "${DIR}/run.sh" '755' '-' 'root:root';
f_mode "${EXE}" '755' '755' 'root:root';
f_mode "${DIR}/conf" '700' '755' 'root:root';
f_mode "${DIR}/conf/bash.sh" '-' '755' 'root:root';
f_mode "${DIR}/conf/.hosts" '755' '-' 'root:root';
f_mode "${DIR}/conf/git" '755' '-' 'root:root';
f_mode "${DIR}/incs" '755' '-' 'root:root';

########## finish
rm -rf "${DEL}" || f_fail 'finish: del DEL';
[[ -n "${MSG}" ]] && f_warn "${MSG}";
f_done 'finish';
